package com.art.coconut.example.service;

import com.art.coconut.change.BaseChangePojo;
import com.art.coconut.change.FinalChangePojo;
import com.art.coconut.core.Coconut;
import com.art.coconut.example.model.Business;
import com.art.coconut.example.model.BusinessDetail;
import com.art.coconut.example.model.Employee;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ProcessService {

    public Business buildSrcBusiness(){
        Business business = new Business();
        business.setId("1");
        business.setBizNum("100111100");
        List<BusinessDetail> businessDetails = new ArrayList<>();
        business.setBusinessDetailList(businessDetails);
        businessDetails.add(buildSrcDetail("11", "1", "A"));
//        businessDetails.add(buildSrcDetail("12", "1", "B"));
        return business;
    }

    public Business buildDstBusiness(){
        Business business = new Business();
        business.setId("1");
        business.setBizNum("10000");
        List<BusinessDetail> businessDetails = new ArrayList<>();
        business.setBusinessDetailList(businessDetails);
        businessDetails.add(buildDstDetail("11", "1", "D"));
        businessDetails.add(BusinessDetail.build("12", "1", "B"));
//        businessDetails.add(buildDstDetail("13", "1", "C"));
        return business;
    }

    public BusinessDetail buildSrcDetail(String id, String bizId, String desc){
        BusinessDetail businessDetail = BusinessDetail.build(id, bizId, desc);
        List<Employee> employeeList = new ArrayList<>();
        employeeList.add(Employee.build("em_1", id, new Date()));
//        employeeList.add(Employee.build("em_2", id, new Date()));
//        employeeList.add(Employee.build("em_3", id, new Date()));
        businessDetail.setEmployeeList(employeeList);
        return businessDetail;
    }

    public BusinessDetail buildDstDetail(String id, String bizId, String desc){
        BusinessDetail businessDetail = BusinessDetail.build(id, bizId, desc);
        List<Employee> employeeList = new ArrayList<>();
        employeeList.add(Employee.build("em_1", id, new Date()));
//        employeeList.add(Employee.build("em_2", id, new Date()));
//        employeeList.add(Employee.build("em_3", id, new Date()));
        businessDetail.setEmployeeList(employeeList);
        return businessDetail;
    }

    public void testCoconut() throws IllegalAccessException, InstantiationException {
        Business b1 = buildSrcBusiness();
        Business b2 = buildDstBusiness();
        List<BaseChangePojo> baseChangePojoList =  Coconut.processObject(b1, b2);
        List<FinalChangePojo> finalChangePojoList = Coconut.getFinaChangeList(null, "BUSINESS", baseChangePojoList, false);
        List<BaseChangePojo> finalBaseChangeProperty = Coconut.getFinalChangeProperty(null, "BUSINESS", baseChangePojoList, false);
        Coconut.prettyPrint(baseChangePojoList, false);
    }
}
